package com.ljh.lottery.controller;

import com.ljh.lottery.common.utils.BeanTransUtil;
import com.ljh.lottery.common.utils.JacksonUtil;
import com.ljh.lottery.pojo.request.CreateActivityRequest;
import com.ljh.lottery.pojo.request.PageRequest;
import com.ljh.lottery.pojo.response.ActivityDetailResponse;
import com.ljh.lottery.pojo.response.ActivityListResponse;
import com.ljh.lottery.pojo.response.CommonResult;
import com.ljh.lottery.pojo.response.CreateActivityResponse;
import com.ljh.lottery.service.ActivityService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Themberfue
 * @date: 2025/4/13 20:08
 * @description:
 */
@RequestMapping("/activity")
@RestController
public class ActivityController {
    private static final Logger log = LoggerFactory.getLogger(ActivityController.class);

    @Resource(name = "activityServiceImpl")
    ActivityService activityService;

    /**
     * 创建活动
     * @param param 创建活动请求
     * @return 创建活动响应
     */
    @PostMapping("/createActivity")
    public CommonResult<CreateActivityResponse> createActivity(@Validated @RequestBody CreateActivityRequest param) {
        // TODO 打印日志
        log.info("createActivity CreateActivityRequest: {}", JacksonUtil.writeValueAsString(param));

        return CommonResult.success(
                BeanTransUtil.tansToCreateActivityResponse(
                        activityService.createActivity(param)));
    }

    /**
     * 获取创建的活动列表
     * @param param 页面参数
     * @return 活动列表
     */
    @GetMapping("/getActivityPageList")
    public CommonResult<ActivityListResponse> getActivityPageList(PageRequest param) {
        // TODO 打印日志
        log.info("getActivityPageList PageRequest: {}", JacksonUtil.writeValueAsString(param));

        return CommonResult.success(
                BeanTransUtil.transToActivityListResponse(
                        activityService.getActivityPageList(param)));
    }

    /**
     * 获取某个活动的详细信息
     * @param activityId 活动 id
     * @return 活动详细信息响应
     */
    @GetMapping("/getActivityDetail")
    public CommonResult<ActivityDetailResponse> getActivityDetail(Long activityId) {
        // TODO 打印日志
        log.info("getActivityDetail activityId: {}", activityId);

        return CommonResult.success(
                BeanTransUtil.transToActivityDetailResponse(
                        activityService.getActivityDetail(activityId)));
    }
}
